/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyThread;

import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author QuangHau
 */
public class Clock extends Thread {

    int time;
    Semaphore semaphore;
    boolean stopThread = false;
    public Clock(int _time, Semaphore _semaphore) {
        time = _time;
        semaphore = _semaphore;
        System.out.println("Bat dong ho");
    }
    
    public void run()
    {
        int i =0;
        while(i<time)
        {
            if(stopThread)
                break;
            
            try {
                Thread.sleep(100);
                i += 100;
            } catch (InterruptedException ex) {
                Logger.getLogger(Clock.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        semaphore.release();
        System.out.println("exit clock");
    }
    
    public void stopClock()
    {
        stopThread = true;
    }
    
    
}
